package com.zx.service.impl;

import com.zx.DAO.MenuDao;
import com.zx.entity.Menu;
import com.zx.service.MenuInte;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 程仟磊
 * @date 2021/7/26
 */
@Service
public class MenuImpl implements MenuInte {
    @Resource
    private MenuDao menuDao;
    @Override
    public List<Menu> findMneuNoRid(String rid) {
        return menuDao.findMneuNoRid(Integer.parseInt(rid));
    }

    @Override
    public List<Menu> findAllFirstMenu() {
        return menuDao.findAllFirstMenu();
    }

    @Override
    public List findTwoMenuByParent(String mid) {
        return menuDao.findTwoMenuByParent(Integer.parseInt(mid));
    }

    @Override
    public int updateMenuById(Menu menu) {
        return menuDao.updateMenuById(menu);
    }

    @Override
    public int deleteMenu(String mid) {
       int i= menuDao.deleterm(Integer.parseInt(mid));
        int i1=0;
       if (i>=0){
          i1=menuDao.deleteMenu(Integer.parseInt(mid));
       }
       return i1;
    }

    @Override
    public int deleteMenuF(String mid) {
        int i= menuDao.deleterm(Integer.parseInt(mid));
       int i1 =menuDao.updateMenuParent(Integer.parseInt(mid));
       int i2=0;
       if (i>=0&&i1>=0){
           i2=menuDao.deleteMenu(Integer.parseInt(mid));
       }
        return i2;
    }

    @Override
    public int addMenu(Menu menu) {
        if (menu.getMparent()==0){
            menu.setMparent(null);
            return menuDao.addMenu(menu);
        }
        return menuDao.addMenu(menu);
    }
}
